<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		 
			
  
    <meta name="twitter:card" content="summary"/>
    
      <meta name="twitter:image" content="https://www.samrainhan.com/images/avatar.png" />
    
  
  
  <meta name="twitter:title" content="Grunt配置文件"/>
  <meta name="twitter:description" content="Gruntfile.js /*global module:false*/ module.exports = function (grunt) { grunt.initConfig({ imagemin: { /* 压缩图片大小 */ dist: { options: { optimizationLevel: 9 //定义 PNG 图片优化水平 }, files: [{ expand: true, cwd: &#39;app/MyCard/&#39;, src: [&#39;**/*.{png,jpg,jpeg}&#39;], // 优化 img 目录下所有 png/jpg/jpeg 图片 dest: &#39;app/build/&#39; // 优化后的图片保存位置"/>
  
  
  
  
    <meta name="twitter:creator" content="@韩雨"/>
  



		
		<meta name="author" content="韩雨">
		<meta name="description" content="学习 &amp;nbsp;&amp;bull;&amp;nbsp; 生活">
		<meta name="generator" content="Hugo 0.52" />
		<title>Grunt配置文件 &middot; sam的小窝</title>
		<link rel="shortcut icon" href="https://www.samrainhan.com/images/favicon.ico">
		<link rel="stylesheet" href="https://www.samrainhan.com/css/style.css">
		<link rel="stylesheet" href="https://www.samrainhan.com/css/highlight.css">

		
		<link rel="stylesheet" href="https://www.samrainhan.com/css/font-awesome.min.css">
		

		
		<link href="https://www.samrainhan.com/index.xml" rel="alternate" type="application/rss+xml" title="sam的小窝" />
		

		
	</head>

    <body>
       <nav class="main-nav">
	
	
		<a href='https://www.samrainhan.com/'> <span class="arrow">←</span>Home</a>
	
	<a href='https://www.samrainhan.com/posts'>Archive</a>
	<a href='https://www.samrainhan.com/tags'>Tags</a>
	<a href='https://www.samrainhan.com/about'>About</a>

	

	
	<a class="cta" href="https://www.samrainhan.com/index.xml">Subscribe</a>
	
</nav>


        <section id="wrapper" class="post">
            <article>
                <header>
                    <h1>
                        Grunt配置文件
                    </h1>
                    <h2 class="headline">
                    Jun 19, 2015 00:00
                    · 483 words
                    · 1 minute read
                      <span class="tags">
                      
                      
                          
                              <a href="https://www.samrainhan.com/tags/grunt">Grunt</a>
                          
                              <a href="https://www.samrainhan.com/tags/config">config</a>
                          
                              <a href="https://www.samrainhan.com/tags/nodejs">nodejs</a>
                          
                      
                      
                      </span>
                    </h2>
                </header>
                
                  
                    <div id="toc">
                      <nav id="TableOfContents">
<ul>
<li>
<ul>
<li><a href="#gruntfile-js">Gruntfile.js</a></li>
<li><a href="#package-json">package.json</a></li>
</ul></li>
</ul>
</nav>
                    </div>
                  
                
                <section id="post-body">
                    

<h2 id="gruntfile-js">Gruntfile.js</h2>

<pre>

/*global module:false*/
module.exports = function (grunt) {
    grunt.initConfig({
    imagemin: {
            /* 压缩图片大小 */
            dist: {
                options: {
                    optimizationLevel: 9 //定义 PNG 图片优化水平
                },
                files: [{
                    expand: true,
                    cwd: 'app/MyCard/',
                    src: ['**/*.{png,jpg,jpeg}'], // 优化 img 目录下所有 png/jpg/jpeg 图片
                    dest: 'app/build/' // 优化后的图片保存位置，覆盖旧图片，并且不作提示
                }]
            }
        },
    uglify: {
        // 这里是uglify任务的配置信息
        buildall: {
        options: {
                    report: "max"//输出压缩率，可选的值有 false(不输出信息)，gzip
                },
        files: [{
        expand: true,     // Enable dynamic expansion.
        cwd: 'app/MyCard/',      // Src matches are relative  this path.
        src: ['**/*.js'], // Actual pattern(s)  match.
        dest: 'app/build/',   // Destination path prefix.
            //          ext: '.min.js',   // Dest filepaths will have this extension.
        }]
        },
        buildcdn: {
        options: {
                    report: "max"//输出压缩率，可选的值有 false(不输出信息)，gzip
                },
        files: [{
        expand: true,     // Enable dynamic expansion.
        cwd: '/home/rain/下载',      // Src matches are relative  this path.
        src: ['*.js'], // Actual pattern(s)  match.
        dest: '/home/rain/下载/build',   // Destination path prefix.
            //          ext: '.min.js',   // Dest filepaths will have this extension.
        }]
        }
    },
    cssmin: {
        buildall: {
        files: [{
        expand: true,     // Enable dynamic expansion.
        cwd: 'app/MyCard/',      // Src matches are relative  this path.
        src: ['**/*.css'], // Actual pattern(s)  match.
        dest: 'app/build/',   // Destination path prefix.
        }]
        }
    },
    htmlmin: {
        buildall: {
        options: {
        collapseBooleanAttributes: true,
        collapseWhitespace: true,
        conservativeCollapse: true,
    //  removeAttributeQuotes: true,
        removeCommentsFromCDATA: true,
    //  removeEmptyAttributes: true,
        removeOptionalTags: true,
    //  removeRedundantAttributes: true,
    //  useShortDoctype: true
            },
        files: [{
        expand: true,     // Enable dynamic expansion.
        cwd: 'app/MyCard/',      // Src matches are relative  this path.
        src: ['**/*.html'], // Actual pattern(s)  match.
        dest: 'app/build/',   // Destination path prefix.
        }]
        }
    }
});
  
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');

  //注册任务
grunt.registerTask('default',['uglify:buildall','imagemin','cssmin','htmlmin']);
grunt.registerTask('js',['uglify:buildall']);
grunt.registerTask('jscdn',['uglify:buildcdn']);
grunt.registerTask('img', ['imagemin']);
grunt.registerTask('css', ['cssmin']);
grunt.registerTask('html', ['htmlmin']);
};

</pre>

<h2 id="package-json">package.json</h2>

<pre>

{
  "name": "temp",
  "devDependencies": {
    "apache-server-configs": "^2.7.1",
    "grunt": "^0.4.5",
    "grunt-autoprefixer": "^1.0.0",
    "grunt-concurrent": "^0.5.0",
    "grunt-contrib-clean": "^0.6.0",
    "grunt-contrib-concat": "^0.5.0",
    "grunt-contrib-connect": "^0.8.0",
    "grunt-contrib-copy": "^0.5.0",
    "grunt-contrib-cssmin": "^0.10.0",
    "grunt-contrib-htmlmin": "^0.3.0",
    "grunt-contrib-imagemin": "^0.8.0",
    "grunt-contrib-jshint": "^0.10.0",
    "grunt-contrib-uglify": "^0.5.1",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-mocha": "^0.4.10",
    "grunt-newer": "^0.7.0",
    "grunt-rev": "^0.1.0",
    "grunt-svgmin": "^0.4.0",
    "grunt-usemin": "^2.3.0",
    "grunt-wiredep": "^1.7.0",
    "jshint-stylish": "^0.4.0",
    "load-grunt-tasks": "^0.4.0",
    "time-grunt": "^0.4.0"
  },
  "engines": {
    "node": ">=0.10.0"
  }
}

</pre>

                </section>
            </article>

            
                <a class="twitter" href="https://twitter.com/intent/tweet?text=https%3a%2f%2fwww.samrainhan.com%2fposts%2f2015-06-19-sample-config-of-grunt%2f - Grunt%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6 "><span class="icon-twitter"> tweet</span></a>

<a class="facebook" href="#" onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
      'facebook-share-dialog',
      'width=626,height=436');
    return false;"><span class="icon-facebook-rect"> Share</span>
</a>

            

            
                <div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = 'samrainblogbygithub'; 

     
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>

            

            
                <ul id="post-list" class="archive readmore">
    <h3>Read more</h3>

    
    
    
        <li>
            <a href="/posts/2019-04-26-c9-move-to-aws-c9/">Cloud9 Move to Aws C9<aside class="dates">Apr 26 2019</aside></a>
        </li>
    
        <li>
            <a href="/posts/2019-02-16-why-build-blog-with-cloud9/">2019 02 16 Why Build Blog With Cloud9<aside class="dates">Feb 16 2019</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-sports-stretching-best-practices/">运动拉伸最佳实践<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-add-2-files-to-tempdb-for-caching/">给tempdb加2个文件做缓存<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-look-for-sql-server-tables-without-a-clustered-index/">如何找到没有聚集索引的表<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-the-continuous-delivery-maturity-model/">持续实施成熟度模型<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-map-of-continuous-delivery/">持续发布的各个阶段<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-how-dropbox-securely-stores-your-passwords/">Dropbox的用户密码加密机制<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-code-inspection-tool-for-net/">NET代码检查工具<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-how-to-make-unique-id/">怎样生成唯一ID<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
</ul>

            

            <footer id="footer">
    
        <div id="social">

	
	
    <a class="symbol" href="">
        <i class="fa fa-facebook-square"></i>
    </a>
    
    <a class="symbol" href="https://github.com/samrain">
        <i class="fa fa-github-square"></i>
    </a>
    
    <a class="symbol" href="">
        <i class="fa fa-twitter-square"></i>
    </a>
    


</div>

    
    <p class="small">
    
       © Copyright 2019 <i class="fa fa-heart" aria-hidden="true"></i> 韩雨
    
    </p>
    <p class="small">
        Powered by <a href="http://www.gohugo.io/">Hugo</a> Theme By <a href="https://github.com/nodejh/hugo-theme-cactus-plus">nodejh</a>
    </p>
</footer>

        </section>

        <script src="https://www.samrainhan.com/js/jquery-3.3.1.min.js"></script>
<script src="https://www.samrainhan.com/js/main.js"></script>
<script src="https://www.samrainhan.com/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>




  
<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
	ga('create', 'UA-37708730-1', 'auto');
	
	ga('send', 'pageview');
}
</script>





    </body>
</html>
